package com.example.mrzhou.lvmm.view.adapter.surround;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mrzhou.lvmm.R;
import com.example.mrzhou.lvmm.commom.utils.ImageLoader;
import com.example.mrzhou.lvmm.entity.surround.scenic.TickListBean;

import java.text.NumberFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Mr.zhou on 2016/10/27.
 */

public class ScenicAdapter extends RecyclerView.Adapter<ScenicAdapter.ScenicViewHolder> {


    private Context context;
    private List<TickListBean> data;

    public ScenicAdapter(Context context, List<TickListBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public ScenicViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ScenicViewHolder(LayoutInflater.from(context).inflate(R.layout.item_list_sur_scenic, parent, false));
    }

    @Override
    public void onBindViewHolder(ScenicViewHolder holder, int position) {
        NumberFormat nf = NumberFormat.getNumberInstance();
        // 保留两位小数
        nf.setMaximumFractionDigits(2);
        ImageLoader.getInstance().displayImage(data.get(position).getMiddleImage(), context, holder.ivScenicImg);
        holder.tvScenicAdress.setText(data.get(position).getProductName());
        holder.tvScenicPartname.setText(data.get(position).getCityName() + "  " + data.get(position).getProvinceName());
        holder.tvScenicJl.setText(nf.format(Double.valueOf(data.get(position).getJuli()) / 100) + "km");
        holder.tvScenicGood.setText(data.get(position).getCommentGood() + "满意");
        holder.tvScenicPrice.setText("¥" + data.get(position).getSellPrice() + "起");
    }

    @Override
    public int getItemCount() {
        return data != null ? data.size() : 0;
    }

    public class ScenicViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_scenic_img)
        ImageView ivScenicImg;
        @BindView(R.id.tv_scenic_adress)
        TextView tvScenicAdress;
        @BindView(R.id.tv_scenic_partname)
        TextView tvScenicPartname;
        @BindView(R.id.tv_scenic_jl)
        TextView tvScenicJl;
        @BindView(R.id.tv_scenic_good)
        TextView tvScenicGood;
        @BindView(R.id.tv_scenic_price)
        TextView tvScenicPrice;

        public ScenicViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
